<?php
App::uses('AppController', 'Controller');
/**
 * Consigners Controller
 *
 * @property Consigner $Consigner
 */
class ConsignersController extends AppController {

/**
 * index method
 *
 * @return void
 */
	public function index() {
		$this->Consigner->recursive = 0;
		$this->set('consigners', $this->paginate());
        $this->pageTitle = '- Consigners';

    }

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		if (!$this->Consigner->exists($id)) {
			throw new NotFoundException(__('Invalid consigner'));
		}
		$options = array('conditions' => array('Consigner.' . $this->Consigner->primaryKey => $id));
		$this->set('consigner', $this->Consigner->find('first', $options));
        $this->pageTitle = '- View a Consigner';

    }

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->Consigner->create();
			if ($this->Consigner->save($this->request->data)) {
				$this->Session->setFlash(__('The consigner has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The consigner could not be saved. Please, try again.'));
			}
		}
        $this->pageTitle = '- Add a Consigner';

    }

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		if (!$this->Consigner->exists($id)) {
			throw new NotFoundException(__('Invalid consigner'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Consigner->save($this->request->data)) {
				$this->Session->setFlash(__('The consigner has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The consigner could not be saved. Please, try again.'));
			}
		} else {
			$options = array('conditions' => array('Consigner.' . $this->Consigner->primaryKey => $id));
			$this->request->data = $this->Consigner->find('first', $options);
		}
        $this->pageTitle = '- Edit a Consigner';

    }

/**
 * delete method
 *
 * @throws NotFoundException
 * @throws MethodNotAllowedException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		$this->Consigner->id = $id;
		if (!$this->Consigner->exists()) {
			throw new NotFoundException(__('Invalid consigner'));
		}
		$this->request->onlyAllow('post', 'delete');
		if ($this->Consigner->delete()) {
			$this->Session->setFlash(__('Consigner deleted'));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('Consigner was not deleted'));
		$this->redirect(array('action' => 'index'));
	}

    public function search() {
        //$this->set('results',$this->Customer->search($this->data['Customer']['q']));

        $keyword=$this->request->data['Consigner']['keyword']; //get keyword from querystring//
        //used simpme or condition with singe value checking
        //replace ModelName with actual name of your Appmodel

        //$this->Session->setFlash($keyword);

        $conditions=array('OR'=>array(
            'Consigner.id LIKE'=> $keyword,
            'Consigner.name LIKE'=> $keyword,
            'Consigner.phone LIKE'=> $keyword));

        $this->set('isFound', $this->Consigner->find('count',array(
                    'conditions'=>$conditions)
            )
        );

        $this->set('list', $this->Consigner->find('all',array(
                    'conditions'=>$conditions)
            )
        );
    }

}
